﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script>
    layui.use(['jquery', 'form', 'laydate', 'common', 'table', 'commonTable', 'optimizeSelectOption'], function () {
        var form = layui.form,
            $ = layui.$,
            commonTable = layui.commonTable,
            table = layui.table,
            common = layui.common;
        var itemId = $.request("itemId");
        //权限字段
        common.authorizeFields('adminform');
        commonTable.rendertable({
            elem: '#currentTableId',
            id: 'currentTableId',
            data: [],
            search: false,
            height: 'full-110',
            limit: 99999,//每页数据 默认
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['count'] //自定义分页布局
                , first: false //不显示首页
                , last: false //不显示尾页
            },
            toolbar: false,//工具栏
            cols: [[
                { type: 'radio' },
                { field: 'F_AreaCode', title: '库区编号', minWidth: 120, sort: true, filter: true  },
                {
                    field: 'F_AreaType', title: '库区类型', width: 120, sort: true, filter: true,
                    templet: function (d) {
                        return top.clients.dataItems["Mes_AreaType"][d.F_AreaType] == null ? "" : top.clients.dataItems["Mes_AreaType"][d.F_AreaType];
                    }
                },
                {
                    field: 'F_EnabledMark', title: '状态', width: 120, sort: true, filter: true,
                    templet: function (d) {
                        if (d.F_EnabledMark == true) {
                            return "<span class='layui-btn layui-btn-normal layui-btn-xs'>有效</span>";
                        } else {
                            return "<span class='layui-btn layui-btn-warm layui-btn-xs'>无效</span>";
                        }
                    }
                },
                { field: 'F_Description', title: '备注', minWidth: 120, sort: true, filter: true },
            ]]
        });
        // 监听双击事件
        table.on('rowDouble(currentTableFilter)', function (obj) {
            var postData = {};
            postData["F_EqpId"] = itemId;
            postData["F_AreaId"] = obj.data.F_Id;
            common.submitPost({
                prompt: "注：您确定要选择{区域编号" + obj.data.F_AreaCode + "}的数据吗？",
                url: "/EquipmentManage/EqpArea/SubmitForm",
                param: postData,
                close:true,
                success: function () {
                    common.parentreload('data-search-btn');
                }
            });
            return false;
        });
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            common.ajax({
                url: "/EquipmentManage/EqpArea/GetAddListJson",
                dataType: 'json',
                data: { itemId: itemId, keyword: data.field.txt_keyword },
                async: false,
                success: function (data) {
                    if (data.data) {
                        table.reload('currentTableId', {
                            data: data.data
                        });
                    }
                }
            });
            return false;
        });
        $('button[lay-filter="data-search-btn"]').click();//按钮刷新
        form.render();
        $(document).on("click", ".layui-table-body table.layui-table tbody tr", function () {
            var index = $(this).attr('data-index');
            var tableBox = $(this).parents('.layui-table-box');
            //存在固定列
            if (tableBox.find(".layui-table-fixed.layui-table-fixed-l").length > 0) {
                tableDiv = tableBox.find(".layui-table-fixed.layui-table-fixed-l");
            } else {
                tableDiv = tableBox.find(".layui-table-body.layui-table-main");
            }
            var checkCell = tableDiv.find("tr[data-index=" + index + "]").find("td div.laytable-cell-radio div.layui-form-radio I");
            if (checkCell.length > 0) {
                checkCell.click();
            }
        });
        //对td的单击事件进行拦截停止，防止事件冒泡再次触发上述的单击事件（Table的单击行事件不会拦截，依然有效）
        $(document).on("click", "td div.laytable-cell-radio div.layui-form-radio", function (e) {
            e.stopPropagation();
        });
        wcLoading.close();
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var postData = {};
            var checkStatus = table.checkStatus("currentTableId").data;
            if (checkStatus.length <= 0) {
                common.modalMsg("未选中数据", "warning");
                return false;
            }
            postData["F_EqpId"] = itemId;
            postData["F_AreaId"] = checkStatus[0].F_Id;
            common.submitPost({
                prompt: "注：您确定要选择{区域编号" + checkStatus[0].F_AreaCode + "}的数据吗？",
                url: "/EquipmentManage/EqpArea/SubmitForm",
                param: postData,
                close: true,
                success: function () {
                    common.parentreload('data-search-btn');
                }
            });
            return false;
        });
    });
</script>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <fieldset class="table-search-fieldset">
                @*<legend>搜索信息</legend>*@
                <div>
                    <form class="layui-form layui-form-pane" action="">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">关键字:</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="txt_keyword" name="txt_keyword" autocomplete="off" class="layui-input" placeholder="">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon">&#xe615;</i> 搜 索</button>
                            </div>
                        </div>
                        <div class="layui-form-item layui-hide">
                            <button class="layui-btn" lay-submit id="submit" lay-filter="saveBtn">确认保存</button>
                        </div>
                    </form>
                </div>
            </fieldset>
            <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        </div>
    </div>
</body>

